<?php

class Uv {
	private $idUV;
	private $nomUV;

	
	//les methodes:
	public function id() { //un getter
		return $this->idUV;
	}
	
	public function nom() { //un getter
		return $this->nomUV;
	}


	
	//Un constructeur
	public function __construct ($nomUV) {
		$this->idUV = null;
		$this->nomUV = $nomUV;

	}
	
	public function create(){
		$nomUv = $this->nomUV;
		$req = "SELECT * FROM UV WHERE nomUv='$nomUV'";
		$res = mysql_query($req) or die ("erreur insertion : UV->create1");
		
		if (mysql_num_rows($res) == 0){ //l'Uv n'existe pas
			$nomUV = $this->nomUV;
			$req = "INSERT INTO UV(nomUV) VALUES ('$nomUV')";
			$res = mysql_query($req) or die ("erreur insertion :  UV->create2");
		}
		else
			return 'Ce nom est déjà utilisé';
	}
	


	public function delete($idUV){
		$req = mysql_query("DELETE FROM UV WHERE 
			idUV = '$idUV'");
		mysql_query($req);
	}

			
	}
	
	public static function getUVById($idUV) { //une fonction statique
		$req = "SELECT * FROM UV WHERE idDep='$idUV'";
		$res = mysql_query($req) or die ("UV-getUVById ");
		
		if (mysql_num_rows($res) == 0) //le produit n'existe pas
			return null;
			
		$tuple = mysql_fetch_array($res);
		$UV = new UV($tuple['nomUV']);
		$UV->idUV = $idUV;
	}
}

?>
